home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Gold Collection
/
Software Vault - The Gold Collection (American Databankers) (1993).ISO
/
cdr05
/
xnot12a.zip
/
SPAWN.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-04
|
8KB
|
336 lines
#include "jam.h"
/*
* Name: Mg 2a
* Spawn CLI for MSDOS (TurboC 1.5)
*
*/
#include "stdlib.h"
#include "def.h"
#include "keyname.h"
#if defined(WINDOWED) || defined (CURSES)
# define CANSPAWN
static char command[NLINE + 1];
static char wincommand[NLINE + 1];
# ifdef MSW
static char makecommand[NLINE + 1] = {"nmake "};
# else
static char makecommand[NLINE + 1] = {"make "};
# endif
#else
# include <process.h>
extern char *getenv();
#endif
static BOOL rn_(nextline, (char *filen, char *lnum));
#ifdef CANSPAWN
spawncli(f, n, k)
int f, n, k;
{
return (winspawn((char *)0, FALSE));
}
spawncli2(f, n, k)
int f, n, k;
{
char buf[NLINE + 1];
int s;
if (command)
epreload(command);
# ifdef MSW
s = ereply("!", buf, NFILEN);
# else
s = ereply("Shell: ", buf, NFILEN);
# endif
if (s != TRUE)
return s;
strcpy(command, buf);
WindowSleepCursor();
s = winspawn(buf, FALSE);
WindowNormalCursor();
return(s);
}
# ifdef MSW
int windowprog(int f, int n)
{
char buf[NLINE + 1];
int s;
if (wincommand)
epreload(wincommand);
s = ereply("WinExec: ", buf, NFILEN);
if (s != TRUE)
return s;
strcpy(wincommand, buf);
WindowSleepCursor();
s = winspawn(buf, TRUE);
WindowNormalCursor();
return(s);
}
# endif /* MSW */
# ifdef SomeUnix
int peerprog(f, n)
int f, n;
{
char buf[NLINE + 1];
int s;
if (wincommand)
epreload(wincommand);
s = ereply("Exec: ", buf, NFILEN);
if (s != TRUE)
return s;
strcpy(wincommand, buf);
WindowSleepCursor();
s = winspawn(buf, TRUE);
WindowNormalCursor();
return(s);
}
# endif
#else /* CANSPAWN */
/*
* On MSDOS, we got no job control like system V, so always
* run a subshell. Bound to "C-C", and used
* as a subcommand by "C-Z". (daveb)
*
* Returns 0 if the shell executed OK, something else if
* we couldn't start shell or it exited badly.
*/
spawncli(f, n, k)
int f, n, k;
{
char *comspec;
int errp = FALSE;
ttcolor(CTEXT);
ttnowindow();
ttmove(nrow-1, 0);
if (epresf != FALSE) {
tteeol();
epresf = FALSE;
}
ttclose();
sgarbf = TRUE; /* Force repaint. */
if ((comspec = getenv("COMSPEC")) == NULL)
errp = -1;
else
errp = spawnl(P_WAIT, comspec, "COMMAND.COM", (char *)NULL);
ttopen();
if(errp == -1)
ewprintf("Failed to create process");
return ( errp );
}
#endif /* WINDOWED */
/* This code has nothing specific to do with spawning a task -
* it does however get compiled with OS specific stuff and
* so I stuck the code in here cause this code knows (sorta) how to
* parse a compile log. Note that on NT the stupid DOS window
* directs stderr and stdout to different locations whereas
* DOS windows under Window 3.1 direct both to the same place
* thus this is only (currently) useful to Windows users, but
* not NT or even UNIX folk. (jam)
*/
sysmake(f, n)
int f, n;
{
#ifdef CANSPAWN
char buf[NLINE + 1];
int s;
if (makecommand)
epreload(makecommand);
s = ereply("!", buf, NFILEN);
if (s != TRUE)
return s;
savebuffers(0, 0); /* files up to date? */
update();
strcpy(makecommand, buf); /* build make command */
WindowSleepCursor();
s = winspawn(buf, FALSE); /* run it */
WindowNormalCursor();
return(s);
#else
return(FALSE);
#endif
}
/* parse spawned-task error file for compile errors
*/
int makeerror(f, n)
int f, n;
{
#ifdef CANSPAWN
BUFFER *bp;
EWINDOW *wp;
if (!(bp = bfind(spawnfilename, FALSE)))
{
ewprintf("Can't find log file [%s].", spawnfilename);
return(FALSE);
}
/* log file ?
*/
if (bp)
{
char fname[NFILEN + 1];
char linenum[20];
char origdir[NFILEN + 1];
if ((wp = popbuf(bp)) == NULL)
return (FALSE);
curbp = bp;
curwp = wp;
thisflag |= CFNEWB;
if (nextline(fname, linenum))
{
/* Force dir back to original for filespecs
* w/o explicit path information
*/
dirfrombp(origdir, bp);
gotodir(origdir);
/* Legal error line might be found, but
* may not provide useful file-seeking info.
* Check the return params for name and line
* number; always echo the error line
*/
if (fname[0])
{
BUFFER *bp;
AddString(fname);
AddKchar(CCHR('J'));
if (bp = bfind(fname, FALSE))
poptobuffer(0, 1); /* hope is same file */
else
poptofilequiet(0, 1); /* get file in cur dir */
if (linenum[0])
{
AddString(linenum);
AddKchar(CCHR('J'));
gotoline(0, 1);
}
}
ewprintf(&wp->w_dotp->l_text[0]); /* log file window */
}
else
ewprintf("No more errors found.");
}
#endif /* WINDOWED */
return (TRUE);
}
#ifdef CANSPAWN
static BOOL nextline(fname, linenum)
register char *fname, *linenum;
{
# if defined(MSW) || defined(SOL) || defined (HP)
for (;;)
{
register char c;
#ifdef HP
int cc_str = 0;
#endif
if (lforw(curwp->w_dotp) == curwp->w_bufp->b_linep)
return(FALSE);
curwp->w_dotp = lforw(curwp->w_dotp);
curwp->w_doto = 0;
c = lgetc(curwp->w_dotp, 0);
/* See if line has filename and linenumber
*/
if (!ISWHITE(c))
{
register int j, i;
BOOL dot = FALSE;
char lbuffer[NLINE];
int x = 0;
#ifdef HP
x += strlen("cc: ");
#endif
j = i = 0;
strcpy(lbuffer, &curwp->w_dotp->l_text[x]);
for (; lbuffer[i]; i++)
{
if (ISWHITE(lbuffer[i]))
break;
# ifdef MSW
/* format is file.c(xx) xx is the line number */
else if ((lbuffer[i] == '(') && dot)
{
i++;
# endif
# if defined(SOL) || defined(HP)
/* SOL: format is "file.c", line xx: xx is line number */
/* HP: format is cc: "file.c", line xx: xx is line number */
else if ((lbuffer[i] == ',') && dot)
{
char *str = ", line ";
int n = (int)strlen(str);
if (strncmp(&lbuffer[i], str, n) != 0)
return(FALSE); /* don't know */
else
i += n;
# endif
/* some errors don't specifiy line numbers, ie LINK
* errors s- return TRUE but zap return params
*/
if (lbuffer[i] && !ISDIGIT(lbuffer[i]))
{
linenum[0] = '\0';
fname[0] = '\0';
}
else
# ifdef MSW
for (j = 0; lbuffer[i] && lbuffer[i] != ')'; )
# else
for (j = 0; lbuffer[i] && lbuffer[i] != ':'; )
# endif
{
linenum[j++] = lbuffer[i++];
linenum[j] = '\0';
}
return(TRUE);
}
else
{
# if defined (SOL) || defined (HP) /* name is quoted, skip quotes */
if (lbuffer[i] == '"')
continue;
# endif
fname[j++] = lbuffer[i];
fname[j] = '\0';
if (lbuffer[i] == '.')
dot = TRUE;
}
}
}
}
# endif /* MSW || SOL */
return (FALSE);
}
#endif /* CANSPAWN */